fix(network-agent): allow dots in sandboxID validation#163
Conversation
|
/cubebot review |
|
Claude finished @fslongjin's task in 1m 10s —— View job PR Review: fix(network-agent): allow dots in sandboxID validation
Verdict: LGTM — the fix is correct and well-aligned with existing patternsThe change ( // Before:
if strings.ContainsAny(sandboxID, `/\.`) || sandboxID == "" {
// After:
if sandboxID == "" || strings.ContainsAny(sandboxID, `/\`) || strings.Contains(sandboxID, "..") {CorrectnessThe fix correctly distinguishes between a single Consistency with codebaseThis now matches exactly the pattern used in if strings.ContainsAny(id, `/\`) || strings.Contains(id, "..") {It also aligns with if strings.ContainsAny(untrusted, `/\`) || untrusted == "." || untrusted == ".." ||
strings.Contains(untrusted, "..") {One subtle difference: SecurityPath traversal protection remains intact:
Suggestion (non-blocking)The existing func TestStateStorePathValidation(t *testing.T) {
store, _ := newStateStore(t.TempDir())
tests := []struct {
id string
wantErr bool
}{
{"valid-id-123", false},
{"cubesandbox-python-slim-3.11-nydus_0", false}, // single dots ok
{"", true}, // empty
{"foo/bar", true}, // forward slash
{"foo\\bar", true}, // backslash
{"foo..bar", true}, // double dot
{"../etc/passwd", true}, // traversal prefix
}
for _, tt := range tests {
_, err := store.path(tt.id)
if (err != nil) != tt.wantErr {
t.Errorf("path(%q) err=%v, wantErr=%v", tt.id, err, tt.wantErr)
}
}
}This mirrors the test coverage that already exists for |
|
@rogeroger-yu Hi, could you please add some unit tests to stabilize this behavior? |
|
@fslongjin okey. |
164bd78 to
1713a7c
Compare
1713a7c to
e15e0a4
Compare
|
After reviewing this, I don't think this is the right way to fix it. The sandbox ID should be designed as a UUID. The root cause here is that when CubeMaster generates the template, it sends the template OCI image name to Cubelet as the sandbox ID. |
e15e0a4 to
16fd291
Compare
|
@fslongjin I agree with your judgment and resubmit a version. I will review it after my hard work. |
|
|
||
| templateID, ok := opts.GetSnapshotTemplateID() | ||
| if !ok { | ||
| if _, ok := opts.GetSnapshotTemplateID(); !ok { |
There was a problem hiding this comment.
This if statement should be dropped.
16fd291 to
5a7bee8
Compare
Cubelet: generate UUID-based sandboxID for snapshot creation
5a7bee8 to
4f8cedb
Compare
|
cc @fslongjin |
Summary
rejected any ID containing
.(dot). IDs likecubesandbox-python-slim-3.11-nydus_0(containing version numbers) were incorrectly flagged as path traversal.
Changed to only reject
/,\, and..— consistent with Cubelet'spathutil.ValidateID()./etc/NetworkManager/dnsmasq.ddoes notexist (hosts using systemd-resolved instead of NM-dnsmasq).
already pre-staged locally.
Root Cause
state_store.go:path()usedstrings.ContainsAny(sandboxID, "/\\.")whichtreats a single
.the same as path separators. A dot in a version string(e.g.
3.11) is perfectly safe — only..is a traversal risk.Test Plan
Original Error